var Ajax = function() {
     var a = {};
     
    var createXMLHttp = function() {
        //Create a ajax instance
        var xmlhttp = null;
        
        //IE7,Mozilla,safari,firefox,Opare......
        if ( window.XMLHttpRequest ) xmlhttp = new XMLHttpRequest();
        
        //Old version IE
        else if ( window.ActiveXObject ) {
            var XMLArray = new Array('MSxml2.XMLHTTP.5.0', 'MSxml2.XMLHTTP.4.0',
                'MSxml2.XMLHTTP.3.0', 'MSxml2.XMLHTTP', 'Microsoft.XMLHTTP');
            var success = false;
            for( i = 0;i < XMLArray.length && ! success; i++ ) {
                try{
                    xmlhttp = new ActiveXObject( XMLArray[i] );	
                    success = true;
                    break;
                } catch(e2) {}
            }
            
            if( ! success ) throw new Error('Fail To Create XMLHttpRequest Object');
        }
        return xmlhttp;
    }
    
    var statechange = function ( xmlhttp, callback ) {
        xmlhttp.onreadystatechange = function (){
            if ( xmlhttp.readyState == 4 ) {
                if ( xmlhttp.status == 200 ) {
                    if ( callback != undefined )   callback(xmlhttp.responseText);  
                } else {
                    throw new Error('Request Error');
                }
            }
        }
    }
    
    a.get = function ( url, args, callback ) {
        //create an ajax object
        var xmlhttp = createXMLHttp();
        statechange(xmlhttp, callback);
        
        if ( args != "" && args != null )
	        if ( url.indexOf('?') != -1 ) url = url + '&' + args;
	        else url = url + '?' + args;
        
        xmlhttp.open('GET', url, true);
        xmlhttp.send();
    }
    
    a.post = function ( url, args, callback ) {
        //create an ajax abject
        var xmlhttp = createXMLHttp();
        statechange(xmlhttp, callback);		

        xmlhttp.open('POST', url, true);
        xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        xmlhttp.send(args);
    }
    
    a.load = function(ele, url, args) {
		var xmlhttp = createXMLHttp();
        statechange(xmlhttp, function(){
			ele.innerHTML = xmlhttp.responseText	
		});
        
        if ( args != "" && args != null )
	        if ( url.indexOf('?') != -1 ) url = url + '&' + args;
	        else url = url + '?' + args;
        
        xmlhttp.open('GET', url, true);
        xmlhttp.send();
	}
    
    return a;
}();
